
/****
 * Copyright (C) 2006 dNux Team
 *                                                            ****
 * This program is free software; you can redistribute it and/or *
 * modify under the terms of the GNU General Public License as   *
 * published by the Free Software Foundation;                    *
 * either version 2 of the License.                              *
 *                                                               *
 * This program is distributed in the hope that it will be       *
 * useful, but WITHOUT ANY WARRANTY; without even the implied    *
 * warranty of without even the implied waranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.          *
 * See the GNU General Public License for more details.          *
 *                                                               *
 * You should have received a copy of the                        *
 * GNU General Public License                                    *
 * along with this program; if not, write to the                 *
 * Free Software Foundation, Inc.,                               *
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
 *                                                               *
 ****                                                         ****/

#ifndef __DCORE_PROCESS_H__
#define __DCORE_PROCESS_H__

/* ##### STRUCT ##### */
struct _d_process_s {
  pid_t pid;              /*<! process id*/
  
  d_string_t prog;    /*<! prog name */
  d_list_t *args;    /*<! arguments list */
  
  int pipeStdOut[2];    /*<! pipe for retrieve the standard out */
  int pipeStdErr[2];    /*<! pipe for retrieve the standard err */
  int pipeStdIn[2];    /*<! pipe for retrieve the standard in  */
  
  time_t last_run;      /*<! time to last lauched process */
  d_bool_t running;   /*<! process is lauched */
};

typedef struct _d_process_s d_process_t;

/* ##### FUNCTION ##### */
void d_process_pipe_init(d_process_t *p_process);
void d_process_pipe_make(d_process_t *p_process);
void d_process_pipe_close_unused(d_process_t *process);
void d_process_pipe_close(d_process_t *process);

d_string_t *d_process_make_args(d_process_t *process);

d_process_t *d_process_new (d_string_t prog);
d_process_t *d_process_new_with_args (d_string_t prog, d_list_t *args);
void         d_process_free (d_process_t **process);

void     d_process_add_arg (d_process_t *process, d_string_t arg);
void     d_process_run (d_process_t *process);
d_bool_t d_process_send_signal(d_process_t *process, int signal);
int      d_process_wait (d_process_t *process);
d_bool_t d_process_is_running (d_process_t *process);

int d_process_get_stdout (d_process_t *process);
int d_process_get_stderr (d_process_t *process);
int d_process_get_stdin (d_process_t *process);

pid_t  d_process_get_pid (d_process_t *process);
time_t d_process_get_last_run (d_process_t *process);

void d_process_set_prog (d_process_t *process, d_string_t prog);
void d_process_set_args (d_process_t *process, d_list_t *args);

#endif /* __DCORE_PROCESS_H__ */
